import { defineStore } from 'pinia'
import { findBrand, findHotLike } from '@/apis/home'

export const homeStore = defineStore('homeStore', {
    state: () => {
        // 品牌分类信息
        return {
            brand: {
                id: 'brand/404',
                name: '品牌',
                sub: [
                    {
                        id: 'brand',
                        children_id: 'brand-children/404',
                        children_name: '品牌推荐',
                    },
                ],
                brands: {},
            },
            hotLikeGoods: [],
        }
    },

    actions: {
        async setBrand() {
            this.brand.brands = await findBrand(9)
        },
        async setHotLikeGoods() {
            const goods = await findHotLike()
            this.hotLikeGoods = this.hotLikeGoods.concat(goods)
        },
    },
    // persist: {
    //     // 开启数据持久化
    //     enabled: true,
    //     strategies: [
    //         {
    //             // 保存的名称
    //             key: 'brandManage',
    //             storage: sessionStorage,
    //         },
    //     ],
    // },
})
